//od机试.中等.字符串迷宫寻找字符串/不能bfs/std::vector<bool>中的坑
// 测试输入
// 2 4
// solo
// aolf
// esol
// 输出 YES

#include <bits/stdc++.h>
using namespace std;
#define PF(...) printf(__VA_ARGS__)
struct Coordinate {
  int row = 0, col = 0;
  // set需要
  bool operator< (const Coordinate& other) const {
    if (row == other.row)
      return col < other.col;
    return row < other.row;
  }
};

int bfsFind(const vector<string> vtMaze, const string& sTarget, Coordinate sPos)
{
  if (vtMaze[sPos.row][sPos.col] != sTarget[0]) {
    return -1;
  }
  vector<Coordinate> dirs = {{0,1}, {0,-1}, {1,0}, {-1,0}};
  int nMaxR = vtMaze.size();
  int nMaxC = vtMaze[0].length();
  set<Coordinate> stVisited;
  queue<tuple<int,int,int> > queChar;  // row, col, len
  queChar.push({sPos.row, sPos.col, 0});  // head char
  int nLen = 1;
  stVisited.insert(sPos);
  while (!queChar.empty()) {
    auto [r, c, index] = queChar.front(); queChar.pop();
    for (auto [dr, dc] : dirs) {
      int prow = r + dr, pcol = c + dc;
      int pIdx = index + 1;
      if (prow < 0 || prow >= nMaxR || pcol < 0 || pcol >= nMaxC) {
        continue ;
      }
      if (stVisited.count({prow, pcol}) > 0) {
        continue;
      }
      if (vtMaze[prow][pcol] != sTarget[pIdx]) {
        continue;
      }
      stVisited.insert({prow, pcol});
      queChar.push({prow, pcol, pIdx});
      nLen = pIdx + 1;
      if (pIdx == sTarget.length() - 1) {
        return pIdx;
      }
    }
  }
  return sTarget.length() == nLen ?  nLen : -1;
}



Coordinate findWord(const vector<string>& vtMaze, const string& sTarget)
{
  // bfs(vtMaze, sTarget);
  // i -> row
  // j -> col
  Coordinate nHeadPos = {-1, -1};
  if (sTarget.length() == 0) {
    return nHeadPos;
  }
  if (vtMaze.size() == 0) {
    return nHeadPos;
  }
  if (vtMaze[0].length() == 0) {
    return nHeadPos;
  }
  for (int i = 0; i < vtMaze.size(); i++) {
    string sLine = vtMaze[i];
    for (int j = 0; j < sLine.length(); j++) {
      if (vtMaze[i][j] != sTarget[0]) {
        continue;
      }
      int nOut = bfsFind(vtMaze, sTarget, {i, j});
      if (nOut >= 0) {
        nHeadPos.row = i;
        nHeadPos.col = j;
        return nHeadPos;
      }
    }
  }
  return nHeadPos;
}


int main_bfs() {
  int n;  // row
  int m;  // col
  do {

  cin >> n >> m;
  string sTarget;
  cin >> sTarget;
  vector<string> vtMaze;
  for (size_t i = 0; i < n; i++) {
    string sTmp;
    cin >> sTmp;
    vtMaze.push_back(sTmp);
  }
  Coordinate nHeadPos = findWord(vtMaze, sTarget);
  if (nHeadPos.row < 0 || nHeadPos.col < 0) {
    printf("NO\n");
  }else {
    printf("%d %d\n", nHeadPos.row + 1, nHeadPos.col + 1);
  }

  }while (true);

  return 0;
}
